/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
 *
 * @file    mapi_osd_client.c
 * @brief   osd client function
 * @author  HiMobileCam NDK develop team
 * @date  2019-7-19
 */

#include "hi_mapi_osd.h"
#include "hi_mapi_osd_define.h"
#include "mapi_comm_inner.h"
#include "hi_comm_ipcmsg.h"
#include "hi_ipcmsg.h"
#include "msg_define.h"
#include "msg_wrapper.h"
#include "msg_osd.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */



HI_S32 HI_MAPI_OSD_Init(const HI_MAPI_OSD_FONTS_S* pstFonts)
{
    MAPI_UNUSED(pstFonts);
    MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "OSD init on the server side,client do noting\n");
    return HI_SUCCESS;
}


HI_S32 HI_MAPI_OSD_Deinit(HI_VOID)
{
    HI_S32 ret;
    HI_U32 modFd = MODFD(HI_MAPI_MOD_OSD, 0, 0);

    ret = MAPI_SendSync(modFd, MSG_CMD_OSD_DEINIT, HI_NULL, 0,
                        HI_NULL);

    if (ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "osd deinit fail, ret:%x\n", ret);
        return ret;
    }

    return HI_SUCCESS;
}


HI_S32 HI_MAPI_OSD_SetAttr(HI_S32 s32OsdIdx, HI_MAPI_OSD_ATTR_S* pstAttr)
{
    /* Check Input Param */
    CHECK_MAPI_NULL_PTR_RET(HI_MAPI_MOD_OSD, pstAttr, HI_MAPI_OSD_ENULL_PTR);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx >= 0, HI_MAPI_OSD_EHANDLE_ILLEGAL);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx < HI_MAPI_OSD_MAX_CNT, HI_MAPI_OSD_EHANDLE_ILLEGAL);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, pstAttr->u32DispNum != 0, HI_MAPI_OSD_EILLEGAL_PARAM);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, pstAttr->u32DispNum <= HI_MAPI_OSD_MAX_DISP_CNT, HI_MAPI_OSD_EILLEGAL_PARAM);

    HI_S32 s32Ret;
    HI_U32 u32ModFd = MODFD(HI_MAPI_MOD_OSD, 0, s32OsdIdx);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_OSD_SET_ATTR, pstAttr, sizeof(HI_MAPI_OSD_ATTR_S),
                           HI_NULL);

    if (s32Ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "set attr fail,OsdHdl:%d,s32Ret:%x\n", s32OsdIdx, s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;
}


HI_S32 HI_MAPI_OSD_GetAttr(HI_S32 s32OsdIdx, HI_MAPI_OSD_ATTR_S* pstAttr)
{
    /* Check Input Param */
    CHECK_MAPI_NULL_PTR_RET(HI_MAPI_MOD_OSD, pstAttr, HI_MAPI_OSD_ENULL_PTR);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx >= 0, HI_MAPI_OSD_EHANDLE_ILLEGAL);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx < HI_MAPI_OSD_MAX_CNT, HI_MAPI_OSD_EHANDLE_ILLEGAL);

    HI_S32 s32Ret;
    HI_U32 u32ModFd = MODFD(HI_MAPI_MOD_OSD, 0, s32OsdIdx);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_OSD_GET_ATTR, (HI_VOID *)pstAttr, sizeof(HI_MAPI_OSD_ATTR_S),
                           HI_NULL);

    if (s32Ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "get attr fail,OsdHdl:%d,s32Ret:%x\n", s32OsdIdx, s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;
}


HI_S32 HI_MAPI_OSD_Start(HI_S32 s32OsdIdx)
{
    /* Check Input Param */
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx >= 0, HI_MAPI_OSD_EHANDLE_ILLEGAL);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx < HI_MAPI_OSD_MAX_CNT, HI_MAPI_OSD_EHANDLE_ILLEGAL);

    HI_S32 s32Ret;
    HI_U32 u32ModFd = MODFD(HI_MAPI_MOD_OSD, 0, s32OsdIdx);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_OSD_START, HI_NULL, 0, HI_NULL);

    if (s32Ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "start osd fail,OsdHdl:%d,s32Ret:%x\n", s32OsdIdx, s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;

}


HI_S32 HI_MAPI_OSD_Stop(HI_S32 s32OsdIdx)
{
    /* Check Input Param */
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx >= 0, HI_MAPI_OSD_EHANDLE_ILLEGAL);
    CHECK_MAPI_BOOL_RET(HI_MAPI_MOD_OSD, s32OsdIdx < HI_MAPI_OSD_MAX_CNT, HI_MAPI_OSD_EHANDLE_ILLEGAL);

    HI_S32 s32Ret;
    HI_U32 u32ModFd = MODFD(HI_MAPI_MOD_OSD, 0, s32OsdIdx);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_OSD_STOP, HI_NULL, 0, HI_NULL);
    if (s32Ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "stop osd fail,OsdHdl:%d,s32Ret:%x\n", s32OsdIdx, s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;

}

HI_S32 HI_MAPI_OSD_Batch(HI_U32 u32Batch, HI_BOOL bShow)
{
    HI_S32 s32Ret;
    HI_U32 u32ModFd = MODFD(HI_MAPI_MOD_OSD, 0, u32Batch);
    s32Ret = MAPI_SendSync(u32ModFd, MSG_CMD_OSD_BATCH, (HI_VOID *)&bShow, sizeof(HI_BOOL),
                           HI_NULL);

    if (s32Ret != HI_SUCCESS) {
        MAPI_ERR_TRACE(HI_MAPI_MOD_OSD, "osd batch fail,batch:%d,s32Ret:%x\n", u32Batch, s32Ret);
        return s32Ret;
    }

    return HI_SUCCESS;

}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */
